<?php
namespace app\index\model;

use think\Model;

class Sign extends Model
{
	public function get_sign_info()
	{
		if(session('user_id')){
			$data = [
				'is_login'=>session('user_id')
			];

			$res = $this->where(['user_id'=>session('user_id'),'sign_date'=>date('Y-m-d')])->find();

			if($res){
				$data['is_sign'] = true;
				$data['sign_num'] = $res->sign_num;
				$data['kiss'] = $this->getkiss($res->sign_num);
			}else{
				$res = $this->where(['user_id'=>session('user_id'),'sign_date'=>date('Y-m-d',strtotime("-1 days"))])->find();
				if($res){
					$data['is_sign'] = false;
					$data['sign_num'] = $res->sign_num;
					$data['kiss'] = $this->getkiss($res->sign_num+1);

				}else{
					$data['is_sign'] = false;
					$data['sign_num'] = 0;
					$data['kiss'] = 5;
				}
			}
		}else{
			$data = [
				'is_login'=>null
			];
		}
		
		return $data;
	}

	public function getkiss($num)
	{
		if($num<=5){
			return 5;
		}elseif($num<=10){
			return 10;
		}elseif($num<=15){
			return 15;
		}else{
			return 20;
		}
	}
}